﻿package blob.characters
{
    import org.flixel.*;

    public class MediumCharacter extends Character
    {
        private var blobMediumImg:Class;
        private var noMerge:int;

        public function MediumCharacter(param1:Number, param2:Number)
        {
            this.blobMediumImg = MediumCharacter_blobMediumImg;
            super(param1, param2);
            loadGraphic(this.blobMediumImg, true, true, 85, 70);
            addAnimation("walk", [1, 2, 3, 4], 5, true);
            addAnimation("idle", [0, 5], 3, true);
            addAnimation("jump", [3], 1, false);
            addAnimation("noMerge", [8, 7], 3, true);
            _moveSpeed = 250;
            _jumpPower = 400;
            width = 54;
            offset.x = 15;
            return;
        }// end function

        override public function merge(param1:Character) : Character
        {
            var _loc_2:* = new LargeCharacter(x, y);
            _loc_2.x = x - width - 5;
            _loc_2.y = this.y + this.height - _loc_2.height;
            if (isOverlapping(_loc_2))
            {
                _loc_2.x = x;
                if (isOverlapping(_loc_2))
                {
                    _loc_2.y = y + height;
                    if (isOverlapping(_loc_2))
                    {
                        _loc_2.kill();
                        this.setCouldntMerge();
                        param1.setCouldntMerge();
                        return null;
                    }
                }
            }
            param1.kill();
            this.kill();
            return _loc_2;
        }// end function

        override public function split() : Array
        {
            var _loc_1:* = new Array();
            var _loc_2:* = new SmallCharacter(x, y);
            _loc_2.y = y + this.height - _loc_2.height;
            var _loc_3:* = new SmallCharacter(x + width / 2, y + this.height - _loc_2.height);
            _loc_1.push(_loc_2, _loc_3);
            this.kill();
            return _loc_1;
        }// end function

        override public function size() : int
        {
            return 2;
        }// end function

        override public function setCouldntMerge() : void
        {
            this.noMerge = 80;
            return;
        }// end function

        override public function update() : void
        {
            if (facing == RIGHT)
            {
                offset.x = 20;
            }
            else
            {
                offset.x = 11;
            }
            if (this.noMerge > 0)
            {
                play("noMerge");
                var _loc_1:String = this;
                var _loc_2:* = this.noMerge - 1;
                _loc_1.noMerge = _loc_2;
            }
            else if (velocity.x != 0 && isTouching(FlxObject.DOWN))
            {
                play("walk");
            }
            else if (!isTouching(FlxObject.DOWN))
            {
                play("jump");
            }
            else
            {
                play("idle");
            }
            super.update();
            return;
        }// end function

    }
}
